package Kolekcje;

import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;


public class TestList {
	public static void main(String[] args) {
		List<Pet> list = new ArrayList<Pet>();
		list.add(new Mouse());
		list.add(new Hamster());
		list.add(new Pug());
		list.add(new Rat());
		list.add(new Mutt());
		System.out.println("1: "+list);
		Hamster h = new Hamster();
		list.add(h);
		System.out.println("2: "+list);
		System.out.println("3: "+list.contains(h)); //sprawdzanie czy ten obiekt się znajduje
		list.remove(h); //usuwanie przez obiekt
		System.out.println("4: "+list);
		Pet p=list.get(2);//obiekt listy
		System.out.println("5: "+p+" "+list.indexOf(p));
		Pet pug = new Pug();//obiekt nie zjaduje się w liście
		System.out.println("6: "+list.indexOf(pug));
		System.out.println("7: "+list.remove(pug));
		list.remove(p);
		System.out.println("8: "+list+ " index 2: "+list.get(2));
		list.add(3, new Mouse());
		System.out.println("9: "+list);
		List<Pet> sub = list.subList(1, 4);
		System.out.println("subList: "+sub);
		System.out.println("10: "+list.containsAll(sub));
		Collections.sort(sub);
		System.out.println("11: "+sub);
		Collections.shuffle(list);
		System.out.println("12: "+list);
		List<Pet> copy=new ArrayList<Pet>(list);
		sub=Arrays.asList(list.get(1), list.get(4));
		System.out.println("sub: "+sub);
		copy.retainAll(sub);
		System.out.println("13: "+copy);
		copy.addAll(list);
		System.out.println("14: "+copy);
		copy.removeAll(sub);
		System.out.println("15: "+copy);
		copy.set(1, new Pug());
		System.out.println("16: "+copy);
		copy.addAll(1, sub);
		System.out.println("17: "+copy);
		System.out.println("18: "+list);
		list.clear();
		System.out.println("19: "+list);
		list.addAll(Arrays.asList(new Pug(), new Mouse(), new Rat()));
		System.out.println("20: "+list);
		Object[] o=list.toArray();
		System.out.println("21: "+o[0]);
		Pet[] pa = list.toArray(new Pet[2]);
		System.out.println("22: "+pa[2]);
		
	}
}
